from django.contrib.auth.mixins import LoginRequiredMixin

from model.models import User


class SuperAdmin(LoginRequiredMixin):
    """ admin user login authentication """

    def dispatch(self, request, *args, **kwargs):
        # Verify login
        from server.utils import Response, Code

        user = request.user
        if not user.is_authenticated:
            return Response.Json(code=Code.NotLogin)
        if user.role not in [User.Role.super_admin]:
            return Response.Json(code=Code.AccessDenied)
        return super().dispatch(request, *args, **kwargs)
